(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(setq package-enable-at-startup nil)
(setq-default indent-tabs-mode t)
(setq backup-directory-alist `(("." . "~/.saves")))
(add-to-list 'auto-mode-alist '("\\.lua2p\\'" . lua-mode))
(straight-use-package 'use-package)

(use-package fennel-mode :straight t)
(use-package moonscript :straight t)
(use-package csound-mode :straight t)
(use-package icicles :straight t
  :config (icy-mode 1))
(use-package company
  :ensure t
  :config (global-company-mode nil))

(use-package company-lua
  :ensure t
  :straight t)

(use-package all-the-icons
  :ensure t :straight t)

(use-package projectile
  :ensure t :straight t
  :config
  (projectile-mode t)
  :init
  (projectile-mode +1)
  :bind
  ("s-p" . projectile-command-map)
  ("C-c p" . projectile-command-map))

(use-package neotree
  :ensure t
  :straight t
  :config (setq projectile-switch-project-action 'neotree-projectile-action)
  :bind
  ("<f8>" . neotree-toggle))

(use-package corral
  :straight t
  :config
  (global-set-key (kbd "M-9") 'corral-parentheses-backward)
  (global-set-key (kbd "M-0") 'corral-parentheses-forward)
  (global-set-key (kbd "M-[") 'corral-brackets-backward)
  (global-set-key (kbd "M-]") 'corral-brackets-forward)
  (global-set-key (kbd "M-{") 'corral-braces-backward)
  (global-set-key (kbd "M-}") 'corral-braces-forward)
  (global-set-key (kbd "M-\"") 'corral-double-quotes-backward))

(use-package dashboard
  :straight t
  :ensure t
  :config
  (set-face-attribute 'dashboard-heading-face nil
		      :family "Hack Nerd Font-10"
		      :weight 'normal
		      :foreground "#6c71c4")

  (set-face-attribute 'dashboard-items-face nil
		      :family "Hack Nerd Font-10"
		      :weight 'normal
		      :foreground "#93a1a1")
  
  (setq dashboard-banner-logo-title nil)
  (setq dashboard-set-init-info t)
  (setq dashboard-set-footer nil)
  (setq dashboard-set-navigator t)
  (setq dashboard-set-heading-icons nil)
  (setq dashboard-set-file-icons nil)
  (setq dashboard-items '((recents  . 15)
                          (bookmarks . 5)
                          (projects . 5)
                          (agenda . 5)
                          (registers . 5)))
  (setq dashboard-startup-banner nil)
  (dashboard-setup-startup-hook))

(use-package solarized-theme  :straight t
  :config
  (load-theme 'solarized-light t)
  (let ((line (face-attribute 'mode-line :underline)))
    (set-face-attribute 'mode-line          nil :overline   line)
    (set-face-attribute 'mode-line-inactive nil :overline   line)
    (set-face-attribute 'mode-line-inactive nil :underline  line)
    (set-face-attribute 'mode-line          nil
			:background "#fdf6e3"
			:box        nil)
    (set-face-attribute 'mode-line-inactive nil :background "#eee8d5")
    (set-face-attribute 'mode-line-inactive nil :box nil)))

(use-package moody :straight t
  :config
  (setq x-underline-at-descent-line t)
  (moody-replace-mode-line-buffer-identification)
  (moody-replace-vc-mode))

(use-package centaur-tabs
  :straight t
  :config
  (centaur-tabs-headline-match)
  (setq centaur-tabs-style "wave"
	centaur-tabs-set-bar 'under
	centaur-tabs-height 32
	centaur-tabs-show-navigation-buttons nil
	centaur-tabs-set-icons t
	centaur-tabs--buffer-show-groups nil
	centaur-tabs-set-modified-marker t
	centaur-tabs-modified-marker "*"
	centaur-tabs-plain-icons t)
  (centaur-tabs-mode 1)
  (centaur-tabs-change-fonts "hack" 100)
  (centaur-tabs-enable-buffer-reordering))

(use-package pdf-tools :straight t)

(use-package racket-mode
  :straight t
  :config
  (add-hook 'racket-mode-hook      #'racket-unicode-input-method-enable)
  (add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable))

(defvar love-exe (executable-find "love"))
(defvar love-project "~/Projects/LGJ_Pana/")

(defun love/launch ()
  (interactive)
  (message "launching love ...")
  (with-current-buffer (current-buffer)
    (start-process-shell-command "love-process" "*love-output*"
				 (concat "cd " (projectile-acquire-root) "&& love ."))))

(defun pp-rebuild ()
  (interactive)
  (message "rebuilding ..")
  (with-current-buffer (current-buffer)
    (start-process-shell-command "building" "*build-output*"
				 (concat "cd " (projectile-acquire-root) "&& ./build.sh"))))

(use-package lua-mode
  :straight t
  :config
  (setq-local company-backends '((company-lua
                                  company-etags
                                  company-dabbrev-code
                                  company-yasnippet)))
  :bind
  ("C-c C-c" . love/launch)
  ("C-c C-r" . pp-rebuild))

;; (use-package robe
;;   :straight t
;;   :config
;;   (add-hook 'ruby-mode-hook 'robe-mode))

;; (use-package love-minor-mode :straight t)

(use-package scribble-mode
  :straight t)

(use-package vterm
  :straight t)

(use-package rainbow-mode
  :straight t
  :config
  (add-hook 'after-init-hook #'rainbow-mode))

(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8-unix)
(global-visual-line-mode)
(scroll-bar-mode -1)
(menu-bar-mode -1)
(setq inhibit-startup-screen t)
(display-line-numbers-mode t)
(tool-bar-mode -1)
(setq show-paren-style 'parenthesis)
(show-paren-mode t)
(set-face-attribute 'show-paren-match nil
		    :background "#eee8d5")
(add-to-list 'default-frame-alist
	     '(font . "Hack Nerd Font-10"))

(recentf-mode 1)
(setq recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)

(defun centaur-tabs-buffer-groups ()
  '("Common"))

(defun fullscreen ()
  "Make the screen fullscreen."
  (interactive)
  (set-frame-parameter nil 'fullscreen
		       (if (frame-parameter nil 'fullscreen) nil 'fullboth)))
